import { mixin } from "@/mixin/index";
import { defineAsyncComponent } from "vue";
import { gets, post,httpAll,OtherHttp } from "@/api/index";
import { openPage,dot, back } from "@/utils/common";
import { Lazyload } from "vant";
import VueClipBoard from 'vue-clipboard2'
let Skeleton = defineAsyncComponent(() => import("@/components/skeleton.vue"));
import i18n from "@/lang/index";
// import zloading from "@/components/loading.vue";
import * as ElementPlusIconsVue from "@element-plus/icons-vue";
// import { getAssetsFile } from "@/utils/common";
export default {
  install(app) {
    app.config.globalProperties.$http = "";
    app.config.globalProperties.$openPage = openPage;
    app.config.globalProperties.$back = back;
    app.config.globalProperties.$dot = dot;
    app.config.globalProperties.$httpAll = httpAll;
    app.config.globalProperties.$get = gets;
    app.config.globalProperties.$post = post;
    app.config.globalProperties.$OtherHttp = OtherHttp;
    app.use(VueClipBoard)
    // app.config.globalProperties.$getImg = getAssetsFile;
    for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
      app.component(key, component);
    }
    // 注册时可以配置额外的选项
    app.use(Lazyload, {
      preLoad: 1.0,
      lazyComponent: true,
      // loading: loadingimg,
    });
    app.use("Skeleton", Skeleton);
    // app.component("zloading", zloading);
    app.use(i18n);

    app.mixin(mixin);
    app.directive("lowlazy", {
      mounted(el, binding) {
        //定义一个观察器，entries为状态改变元素的数组
        let observer = new IntersectionObserver((entries) => {
          // 遍历
          entries.forEach((item) => {
            if (item.isIntersecting) {
              // 获取该元素
              let img:any = item.target;
              // 重新设置src值
              img.src = binding.value;
              //取消对该元素的观察
              observer.unobserve(img);
            }
          });
        },{
         
        });
        // 为 img 标签添加一个观察
        observer.observe(el);
      },
   
    });
    app.directive("dawnload", {
      beforeMount(el, binding) {
        // 绑定下拉事件
        el.addEventListener("touchstart", function () {
          if (this.scrollTop === 0) {
            binding.value(); // 调用handleRefresh方法
          }
        });
      },
    });
  },
};
